Skip to content

Add integration tests for Go To Definition - #5983

Merged
davidwengier merged 10 commits into
dotnet:mainfrom
davidwengier:GoToDefnIntegrationTests
Jan 31, 2022
Merged

davidwengier merged 10 commits into
dotnet:mainfrom
davidwengier:GoToDefnIntegrationTests

Conversation

@davidwengier

Copy link
Copy Markdown
Member

Fixes #5957

@davidwengier
davidwengier force-pushed the GoToDefnIntegrationTests branch from a16bb90 to f69b60a Compare January 17, 2022 02:47

@NTaylorMullen NTaylorMullen left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool to see this all come together and how human readable it all is.

@ryanbrandenburg ryanbrandenburg left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks really good, just a couple of quibbles about specifics what we'll want Sam's input on. I think I'll write a README for this project with some do's and don'ts if Sam confirms what I said about DTE, cause otherwise it'll be pretty had for people to know that kind of stuff.

How did you find working on it? You certainly got it done faster than I thought so hopefully that means it was breezy? Did you have any suggestions/complaints for either the Framework or this project?

{
var dte = await GetRequiredGlobalServiceAsync<SDTE, EnvDTE.DTE>(cancellationToken);

return dte.ActiveWindow.Caption == windowTitle;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better if we were able to do like view.ActiveWindow_Changed += ... so we're doing less busy-waiting, but such an API might not exist.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't even see a way to get the filename/window title from the active view :(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I figured that was probably the case but wanted to be sure.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't even see a way to get the filename/window title from the active view :(

TestServices.Shell.GetActiveWindowCaptionAsync. And it doesn't use DTE.

@davidwengier

Copy link
Copy Markdown
Member Author

@ryanbrandenburg Updated with your "wait for classification in initialize" idea, if you want to have another look. Also added a version check instead of skipping that one test, curious to see if it works in CI :)

@ryanbrandenburg ryanbrandenburg left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! I'd like to get @sharwell's review to make sure that we're staying on the "Golden Path" WRT DTE usage.

public async Task GoToDefinition_ComponentAttribute()
{
var version = await TestServices.Shell.GetVersionAsync(HangMitigatingCancellationToken);
if (version < new System.Version(17, 1, 32113, 165))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed microsoft/vs-extension-testing#101. I think this'd be nice to have as part of the framework. Maybe instead of returning ("Success") we should do Assert.Ignore("Wrong VS Version"); so we know the test didn't really run.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I was looking for Assert.Inconclusive but didn't notice Ignore.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. no Assert.Ignore in xUnit 😛

{
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

var dte = await GetRequiredGlobalServiceAsync<SDTE, EnvDTE.DTE>(cancellationToken);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 DTE should be avoided where possible. In this case, use IOleCommandTarget:

var dispatcher = await GetRequiredGlobalServiceAsync<SUIHostCommandDispatcher, IOleCommandTarget>(cancellationToken);
ErrorHandler.ThrowOnFailure(dispatcher.Exec(commandGuid, commandId, (uint)OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT, IntPtr.Zero, IntPtr.Zero));

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DTE should be avoided where possible

Is there a quick summary as to why?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the best case, it's slow. In the worst case, it's broken/outdated/legacy.

DTE is a legacy automation wrapper around other public APIs. The first step to moving to modern APIs is to unwrap the calls so we can understand the true underlying APIs involved.

@davidwengier
davidwengier requested a review from sharwell January 26, 2022 11:19
@davidwengier

Copy link
Copy Markdown
Member Author

Mergin'. Follow up can always come in a follow up. I suspect that's why they call it that.

@davidwengier
davidwengier merged commit 58ca88a into dotnet:main Jan 31, 2022
@davidwengier
davidwengier deleted the GoToDefnIntegrationTests branch January 31, 2022 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GoToDefinition Integration Tests

4 participants